package com.gk.app
{
	import com.gk.util.LoadObject;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.geom.Utils3D;

	/**
	 *系统工具类    Game Tools
	 * @author Nestor
	 * 
	 */
	public class GT
	{
		public function GT()
		{
		}
		
		
		/**
		 *画一个矩形 
		 * @param w
		 * @param h
		 * @param lineColor
		 * @param fillColor
		 * @param lineSize
		 * @param alpha
		 * @return 
		 * 
		 */
		public static function getRectGraphic(w:int,
											  h:int,
											  lineColor:uint,
											  fillColor:uint,
											  lineSize:int=1,
											  lineAlpha:Number=1,
											  fillAlpha:Number=1):Sprite {
			var sp:Sprite = new Sprite(); 
			sp.graphics.lineStyle(lineSize, lineColor, lineAlpha);
			sp.graphics.beginFill(fillColor, fillAlpha);
			sp.graphics.drawRect(0,0,w,h);
			sp.graphics.endFill();
			return sp;
		}
		/**
		 *移除所有子级 
		 * @param doc
		 * 
		 */		
		public static function clearChildren(doc:DisplayObjectContainer):void{
			while(doc.numChildren>0){
				doc.removeChildAt(0);
			}
		}
		/**
		 *获取图片 
		 * @param doc 图片容器
		 * @param url 图片地址
		 * @param w	宽  如果不设 为实际宽
		 * @param h 高  如果不设 为实际高
		 * 
		 */		
		public static function getImage(doc:DisplayObjectContainer,url:String,isDomain:Boolean = false,w:int=0,h:int=0):void{
			clearChildren(doc);
			new LoadObject(url,imgOK,null,isDomain);
			function imgOK(img:DisplayObject):void
			{
				doc.addChild(img);
				if(w !=0) img.width = w;
				if(h !=0) img.height = h;
			}
		}
		
		
		
		
		/**
		 * 弹出窗口 
		 * @param target
		 * 
		 */		
		public static function popupWindow(target:DisplayObject,isLock:Boolean = true,isClear:Boolean = false):void{
			if(isClear){
				clearChildren(SYS.POP);
			}
			if(isLock){
				var g:Graphics = SYS.POP.graphics;
				g.clear();
				g.beginFill(0,0.1);
				g.drawRect(0,0,SYS.SYS_WIDTH,SYS.SYS_HEIGHT);
				g.endFill();
			}
			SYS.POP.addChild(target);
			target.x = SYS.SYS_WIDTH/2-target.width/2;
			target.y = SYS.SYS_HEIGHT/2-target.height/2;
		}
		/**
		 *移除窗口 
		 * @param target
		 * @param isLock  是否移除锁屏
		 * 
		 */		
		public static function closeWindow(target:DisplayObject,isLock:Boolean = true):void{
			if(SYS.POP.contains(target)){
				SYS.POP.removeChild(target);
			}
			if(isLock){
				SYS.POP.graphics.clear();
			}
		}
	}
}